package com.eastfair.builder.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.core.exception.BizException;
import com.eastfair.home.api.BuilderRepairReportFeign;
import com.eastfair.home.dto.BuilderRepairReportDTO;
import com.eastfair.home.entity.BuilderRepairReport;
import com.eastfair.home.vo.BuilderRepairReportVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 搭建商报修申请.
 *
 * @author dqq
 * @date 2022 /11/24
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/builderRepairReport")
@Api(value = "BuilderRepairReport", tags = "搭建商报修申请")
@PreAuth(replace = "home:builderRepairReport:")
public class BuilderBuilderRepairReportController {

    @Resource
    private BuilderRepairReportFeign builderRepairReportFeign;

    /**
     * 查询搭建商报修申请列表VO.
     *
     * @param pageParams the page params
     * @return the r
     */
    @ApiOperation("查询搭建商报修申请列表VO")
    @PostMapping("/query/builderRepairReport")
    public R<Page<BuilderRepairReportVO>> queryBuilderRepairReport(@RequestBody PageParams<BuilderRepairReportDTO> pageParams) {
        log.info("queryBuilderRepairReport - 查询搭建商报修申请列表VO, pageParams={}", pageParams);
        try {
            return builderRepairReportFeign.queryBuilderRepairReport(pageParams);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 报修单号获取搭建报修申请VO.
     *
     * @param repairReportNumber the repair report number
     * @return the by report repair number
     */
    @ApiOperation("报修单号获取搭建报修申请VO")
    @GetMapping("/get/{repairReportNumber}")
    public R<BuilderRepairReportVO> getByReportRepairNumber(@PathVariable("repairReportNumber") String repairReportNumber) {
        log.info("getByReportRepairNumber - 报修单号获取搭建报修申请VO, repairReportNumber={}", repairReportNumber);
        try {
            return builderRepairReportFeign.getByReportRepairNumber(repairReportNumber);
        } catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 保存搭建商报修申请.
     *
     * @param builderRepairReportDTO the repair report dto
     * @return the r
     */
    @ApiOperation("保存搭建商报修申请")
    @SysLog("添加报修申请")
    @PostMapping("/save")
    public R<BuilderRepairReport> saveBuilderRepairReport(@RequestBody BuilderRepairReportDTO builderRepairReportDTO) {
        log.info("saveBuilderRepairReport - 保存搭建商报修申请, repairReportDTO={}", builderRepairReportDTO);
        try {
            return builderRepairReportFeign.saveBuilderRepairReport(builderRepairReportDTO);
        }  catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 更新搭建商报修申请.
     *
     * @param builderRepairReportDTO the repair report dto
     * @return the r
     */
    @ApiOperation("更新搭建商报修申请")
    @SysLog("修改报修申请")
    @PostMapping("/update")
    public R<BuilderRepairReport> updateBuilderRepairReport(@RequestBody BuilderRepairReportDTO builderRepairReportDTO) {
        log.info("updateBuilderRepairReport - 更新搭建商报修申请, repairReportDTO={}", builderRepairReportDTO);
        try {
            return builderRepairReportFeign.updateBuilderRepairReport(builderRepairReportDTO);
        }  catch (BizException e) {
            return R.fail(e);
        }
    }

    /**
     * 取消搭建商报修申请.
     *
     * @param repairReportNumber the repair report number
     * @return the r
     */
    @ApiOperation("取消搭建商报修申请")
    @SysLog("取消报修申请")
    @GetMapping("/cancel/{repairReportNumber}")
    public R<Boolean> cancelBuilderRepairReport(@PathVariable("repairReportNumber") String repairReportNumber) {
        log.info("cancelRepairReport - 取消搭建商报修申请={}", repairReportNumber);
        try {
            return builderRepairReportFeign.cancelBuilderRepairReport(repairReportNumber);
        }  catch (BizException e) {
            return R.fail(e);
        }
    }
}